import { friendlyDate } from './util.js'
const BASE_URL = 'http://127.0.0.1:3000'

export const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			success: res => {
				if(res.statusCode !== 200) {
					return uni.showToast({
						title: '获取数据失败'
					})
				}
				if(res.data.res && res.data.res[0].datetime) {
					res.data.res.forEach(item => {
						item.datetime = friendlyDate(new Date(item.datetime))
					})
				}
				resolve(res)
			},
			fail: err => {
				uni.showToast({
					title: '接口请求失败'
				})
				reject(err)
			}
		})
	})
}